package au.com.helloweb.androidgamepractice.planegame2;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;

public class GameMenu {
	private Bitmap bmpMenu;//menu background
	private Bitmap bmpButton,bmpButtonPress;
	private int btnX,btnY;
	private boolean isPress;
	
	public GameMenu(Bitmap bmpMenu, Bitmap bmpButton, Bitmap bmpButtonPress){
		this.bmpMenu = bmpMenu;
		this.bmpButton = bmpButton;
		this.bmpButtonPress = bmpButtonPress;
		btnX = MySurfaceView.screenW/2 - bmpButton.getWidth()/2;
		btnY = MySurfaceView.screenH - bmpButton.getHeight();
		isPress = false;
	}
	
	//draw menu
	public void draw(Canvas canvas, Paint paint){
		canvas.drawBitmap(bmpMenu, 0, 0,paint);
		if(isPress){
			canvas.drawBitmap(bmpButtonPress,btnX,btnY, paint);
		}else{
			canvas.drawBitmap(bmpButton, btnX, btnY,paint);
		}
	}
	
	public void onTouchEvent(MotionEvent event){
		int pointX = (int)event.getX();
		int pointY = (int)event.getY();
		
		if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE){
			//check user click button or not
			if(pointX > btnX && pointX <(btnX+bmpButton.getWidth()) && pointY>btnY && pointY<(btnY+bmpButton.getHeight())){
				isPress = true;
			}else{
				isPress = false;
			}
		}else if(event.getAction() == MotionEvent.ACTION_UP){// move up
			if(pointX > btnX && pointX <(btnX+bmpButton.getWidth()) && pointY>btnY && pointY<(btnY+bmpButton.getHeight())){
				isPress = false;
				MySurfaceView.gameState = MySurfaceView.GAMING;
			}
		}
	}
}
